package com.zs.members.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gsj.common.pojo.R;
import com.zs.members.pojo.entity.Level;
import com.zs.members.dao.LevelMapper;
import com.zs.members.pojo.vo.LevelVo;
import com.zs.members.service.ILevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张硕
 * @since 2021-07-24
 */
@Service
public class LevelServiceImpl extends ServiceImpl<LevelMapper, Level> implements ILevelService {
    @Autowired
    private LevelMapper levelMapper;

    @Override
    public R get(Integer currentPage, Integer pageSize, LevelVo levelVo) {
        Page<Level> levelPage = new Page<>(currentPage, pageSize);
        QueryWrapper<Level> wrapper = new QueryWrapper<>();
        if (levelVo.getId()!=null){
            wrapper.like("id",levelVo.getId());
        }
        if (StringUtils.isNotEmpty(levelVo.getName())){
            wrapper.like("name",levelVo.getName());
        }
        if (StringUtils.isNotEmpty(levelVo.getNote())){
            wrapper.like("note",levelVo.getNote());
        }
        Page<Level> page = levelMapper.selectPage(levelPage, wrapper);

        return R.ok().put("records",page.getRecords()).put("total",page.getTotal());
    }
}
